import { transformTree } from '@web-utils/core'

function buildMenus(menuItems) {
  const items = []
  if (menuItems) {
    const menus = transformTree(menuItems, transfer)

    items.push(...menus)
  }
  if (process.env.NODE_ENV === 'development') {
    items.push({
      id: -1,
      icon: 'el-icon-setting',
      path: '/playground',
      title: 'Playground'
    })
  }
  return items
}

function transfer(item) {
  return {
    id: item.id,
    icon: item.icon,
    path: item.path,
    title: item.name
  }
}

export default {
  leftMenus(state) {
    const leftMenu = state.menu
    return buildMenus(leftMenu)
  },
  isTempUser(state) {
    return state.userType === 'temp'
  }
}
